<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        

        
        <a-row :gutter="24">
          

        <!-- 姓名手机号查询 -->
      <span><a-col :xl="5" :lg="7" :md="8" :sm="24">
          <a-form-item label="姓名：">
            <a-input placeholder="请输入姓名" v-model="queryParam.name" ></a-input>
          </a-form-item>
        </a-col></span>

      <span><a-col :xl="5" :lg="7" :md="8" :sm="24">
          <a-form-item label="手机号：">
            <a-input placeholder="请输入手机号码" v-model="queryParam.mobile" ></a-input>
          </a-form-item>
        </a-col></span>

         <span>
        <a-button @click="searchQuery" type="primary" style="margin-left:16px">查询</a-button>
        <a-button @click="searchReset" type="primary" style="margin-left:16px">重置</a-button>
      </span>
        </a-row>
      </a-form>

     
      

        




    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('活动订单表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <!-- 表单展示 -->
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <temple-activity-order-modal ref="modalForm" @ok="modalFormOk"></temple-activity-order-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import TempleActivityOrderModal from './modules/TempleActivityOrderModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
import { filterObj } from '../../../utils/util'
import { getAction } from '../../../api/manage'

  export default {
    name: 'TempleActivityOrderList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      TempleActivityOrderModal,
    },
    data () {
      return {
       
        // 查询参数
        queryParam:{
          name:"",
          mobile:"",
          activity_category_id:""
        },
        //翻页页面设置
        ipagination:{
          current:1,
          pageSize:10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        description: '活动订单表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'活动id',
            align:"center",
            dataIndex: 'activityId_dictText'
          },
          {
            title:'活动种类id',
            align:"center",
            dataIndex: 'activityCategoryId_dictText'
          },
          {
            title:'微信昵称',
            align:"center",
            dataIndex: 'userId_dictText',
            customRender:(text)=>(text ? decodeURIComponent(text) : ''),
          },
          {
            title:'姓名',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'手机号',
            align:"center",
            dataIndex: 'mobile'
          },
          {
            title:'金额',
            align:"center",
            dataIndex: 'amount'
          },
          {
            title:'是否支付',
            align:"center",
            dataIndex: 'isPay',
            customRender: (text) => (text ? filterMultiDictText(this.dictOptions['isPay'], text) : ''),
          },
          {
            title:'报名渠道',
            align:"center",
            dataIndex: 'payChannel_dictText'
          },
          {
            title:'支付凭证',
            align:"center",
            dataIndex: 'payVoucher',
            scopedSlots: {customRender: 'imgSlot'}
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          // list: "/temple.order/templeActivityOrder/list",
          delete: "/temple.order/templeActivityOrder/delete",
          deleteBatch: "/temple.order/templeActivityOrder/deleteBatch",
          exportXlsUrl: "/temple.order/templeActivityOrder/exportXls",
          importExcelUrl: "temple.order/templeActivityOrder/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.$set(this.dictOptions, 'isPay', [{text:'是',value:'Y'},{text:'否',value:'N'}])
    // this.getSuperFieldList();
    this.loadData();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      // getSuperFieldList(){
      //   let fieldList=[];
      //   fieldList.push({type:'string',value:'activityId',text:'活动id',dictCode:"temple_activity,title,id"})
      //   fieldList.push({type:'string',value:'activityCategoryId',text:'活动种类id',dictCode:"temple_activity_category,name,id"})
      //   fieldList.push({type:'string',value:'userId',text:'用户id',dictCode:"temple_user,nick_name,id"})
      //   fieldList.push({type:'string',value:'name',text:'姓名',dictCode:''})
      //   fieldList.push({type:'string',value:'mobile',text:'手机号',dictCode:''})
      //   fieldList.push({type:'BigDecimal',value:'amount',text:'金额',dictCode:''})
      //   fieldList.push({type:'switch',value:'isPay',text:'是否支付'})
      //   fieldList.push({type:'string',value:'payChannel',text:'报名渠道',dictCode:'pay_channel'})
      //   fieldList.push({type:'string',value:'payVoucher',text:'支付凭证',dictCode:''})
      //   this.superFieldList = fieldList
      // },
      // 表单查询
      async loadData (arg)
      {
        if(arg==1)
        {
          this.ipagination.current=1;
        }
        var param = this.getQueryParams();
        this.loading=true;
        getAction('/temple.order/templeActivityOrder/list',param).then(res=>{
          this.dataSource = res.result.records;
          this.ipagination.total = res.result.total;
        }).finally(()=>{this.loading=false});
        
      },
      //获取查询参数
      getQueryParams(){
        var param = Object.assign({},this.queryParam);
        param.field = this.getQueryField();
        param.pageNo = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        return filterObj(param)
      },
      //查询按钮实现
      searchQuery(){
        this.loadData();
      },
      //查询范围
      getQueryField(){
        let str = ',';
        for(let a = 0;a<this.columns.length;a++)
        {
          str += ','+ this.columns[a].dataIndex;
        }
        return str;
      },
      //重置按钮实现
      searchReset(){
        var that = this;
        // 重置查询数据
        that.queryParam={};
        //发起新的查询请求
        this.loadData(this.ipagination.current);
      }

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>